package org.lg.web.controller;

import org.lg.config.*;
import org.lg.dto.BaseDto;
import org.lg.dto.MessageEnum;
import org.lg.entity.Course;
import org.lg.page.PageInfo;
import org.lg.service.CourseService;
import org.lg.service.impl.CourseServiceImpl;

/**
 * 学生类的控制器 门卫 对url的响应处理
 */
@Controller("/courseController")
public class CourseController {
    @Resource
    CourseService courseService;
    /**
     * 查询全部学生 示例 无参数方法
     * @return
     */
    @RequestMapping("/getCourses")
    @ResponseBody
    public BaseDto getAllCourses() throws Exception {
        return  courseService.getAllCourses();
    }

    @RequestMapping("/getCourseByPage")
    @ResponseBody
    public BaseDto getCourseByPage(@RequestBody PageInfo pageInfo) throws Exception {
        return  courseService.getCourseByPage(pageInfo);
    }


    /**
     * 根据主键查询 示范简单参数
     * @param cno
     * @return
     */
    @RequestMapping("/getCourseById/{id}")
    @ResponseBody
    public BaseDto getCourseById(String cno) throws Exception{
        return  courseService.getCourseByCno(cno);
    }
    /*

     */
    @RequestMapping("/addCourse")
    @ResponseBody
    public BaseDto addCourse(@RequestBody Course course) throws Exception{
        courseService.addCourse(course);
        BaseDto dto = new BaseDto(MessageEnum.ADDTEACHERSUCCESS,course);
        return  dto;
    }

    @RequestMapping("/editCourse")
    @ResponseBody
    public BaseDto editCourse(@RequestBody Course course) throws Exception {
        courseService.editCourse(course);
        BaseDto dto = new BaseDto(MessageEnum.ADDTEACHERSUCCESS,course);
        return  dto;
    }
    @RequestMapping("/cancelCourse")
    public BaseDto cancelCourse(String courseJson){
        BaseDto dto = new BaseDto(MessageEnum.GETTEACHERBYIDSUCCESS);
        return  dto;
    }
}

